#ifndef __L0032_0_DXTINFO_H__
#define __L0032_0_DXTINFO_H__

typedef uint32_t entry_handle;

#define INVALID_ENTRY_HANDLE			(entry_handle)0xFFFFFFFF

#define L0032_DXT_CONF_PATH						"/home/devel/config"
#define L0032_DXT_CFG_SUFFIX					".ini"

// field name define.
#define L0032_DXT_DXTABLE_FIELD_APPNAME			"appname"
#define L0032_DXT_DXTABLE_FIELD_PARSELIB		"parselib"
#define L0032_DXT_DXTABLE_FIELD_ENTRYLIST		"entrylist"
#define L0032_DXT_DXTABLE_FIELD_REFERLIST		"refentrylist"

#define L0032_DXT_ENTRY_FIELD_ENABLE 			"enable"
#define L0032_DXT_ENTRY_FIELD_NAME				"name"
#define L0032_DXT_ENTRY_FIELD_DESC				"desc"
#define L0032_DXT_ENTRY_FIELD_TYPE				"type"
#define L0032_DXT_ENTRY_FIELD_SIZE				"size"
#define L0032_DXT_ENTRY_FIELD_READWRITE			"readwrite"
#define L0032_DXT_ENTRY_FIELD_POINTLIST 		"pointlist"
#define L0032_DXT_ENTRY_FIELD_POINTCOUNT		"pointcount"
#define L0032_DXT_ENTRY_FIELD_POINTLISTCOUNT	"pointlistcount"
#define L0032_DXT_ENTRY_FIELD_VALUENUM			"valueenum"

// data limit define.
#define L0032_DXT_NAME_MAX_LEN					32
#define L0032_DXT_PATH_MAX_LEN					256
#define L0032_DXT_DESC_MAX_LEN					64
#define L0032_DXT_APP_ENTRY_MAX_NUM				23
#define L0032_DXT_APP_REFENTRY_MAX_NUM			5

// data enum define.
#define L0032_DXT_FIELDVALUE_TRUE		1
#define L0032_DXT_FIELDVALUE_FALSE		0

// i8,i16,i32,i64,u8,u16,u32,u64,string
#define L0032_DXT_ENTRY_FIELDVALUE_I8	"i8"
#define L0032_DXT_ENTRY_FIELDVALUE_U8	"u8"
#define L0032_DXT_ENTRY_FIELDVALUE_I32	"i32"
#define L0032_DXT_ENTRY_FIELDVALUE_U32	"u32"
#define L0032_DXT_ENTRY_FIELDVALUE_I64	"i64"
#define L0032_DXT_ENTRY_FIELDVALUE_U64	"u64"
#define L0032_DXT_ENTRY_FIELDVALUE_STRING	"string"

#define L0032_DXT_FIELDVALUE_RW		"rw"
#define L0032_DXT_FIELDVALUE_RO		"ro"

#define L0032_DXT_FLAGS_POINT_READWRITE		0x10000000
#define L0032_DXT_FLAGS_POINT_I8			0x00000001
#define L0032_DXT_FLAGS_POINT_U8			0x00000002
#define L0032_DXT_FLAGS_POINT_I32			0x00000004
#define L0032_DXT_FLAGS_POINT_U32			0x00000008
#define L0032_DXT_FLAGS_POINT_F32			0x00000010
#define L0032_DXT_FLAGS_POINT_I64			0x00000020
#define L0032_DXT_FLAGS_POINT_U64			0x00000040
#define L0032_DXT_FLAGS_POINT_F64			0x00000080
#define L0032_DXT_FLAGS_POINT_BUF			0x00000100

#define L0032_DXT_FLAGS_POINT_NUMBERTYPE		(L0032_DXT_FLAGS_POINT_I8|L0032_DXT_FLAGS_POINT_U8|L0032_DXT_FLAGS_POINT_I32|\
L0032_DXT_FLAGS_POINT_U32|L0032_DXT_FLAGS_POINT_F32|L0032_DXT_FLAGS_POINT_I64|L0032_DXT_FLAGS_POINT_U64|L0032_DXT_FLAGS_POINT_F64)

#define L0032_DXT_ISWRITABLE(ENTRY)			((((ENTRY)->flags)&L0032_DXT_FLAGS_POINT_READWRITE))
#define L0032_DXT_ISENTRYTYPE(ENTRY, TYPE)				((((ENTRY)->flags)&L0032_DXT_FLAGS_POINT_##TYPE))

struct l0032_xtable_valueenum {
	char valdesc[L0032_DXT_DESC_MAX_LEN];
	int  val;
};

#define L0032_DXT_FLAGS_POINT_NAMED			0x00000200
#define L0032_DXT_FLAGS_POINT_VALUEENUM		0x00000400
struct l0032_xtable_namedpoint {/* named point which have point name, description, defined value and value description */
	char name[L0032_DXT_NAME_MAX_LEN];
	char desc[L0032_DXT_DESC_MAX_LEN];
	int nvalues;
	struct l0032_xtable_valueenum *valueenum;
	uint32_t flags;
};

struct l0032_xtable_entry {
	entry_handle hentry;
	char name[L0032_DXT_NAME_MAX_LEN];
	char desc[L0032_DXT_DESC_MAX_LEN];
	uint32_t flags;
	int npoints;
	struct l0032_xtable_namedpoint *namedpoints;	// for POINT_ENUM type usage, otherwise is NULL
};

/* user oriented dataxchgtable interface
 * entry_index is hentry_kernel actually in dataxchgtable.c
 */
struct l0032_xtable {
	size_t sz;
	char appname[L0032_DXT_NAME_MAX_LEN];
	char parselib[L0032_DXT_NAME_MAX_LEN];

	int nentries;
	int nrefentries;

	struct l0032_xtable_entry *entries;
	struct l0032_xtable_entry *refentries;
};

int l0032_xtable_write(entry_handle hentry, int pointno, void* addr);
int l0032_xtable_read(entry_handle hentry, int pointno, void* addr, size_t sz);
int l0032_xtable_load_conf(struct l0032_xtable *xtable, const char* iniconf);
struct l0032_xtable * l0032_xtable_open(const char* shmname, int bcreate);
void l0032_xtable_close();
void l0032_xtable_dump_conf(struct l0032_xtable *xtable);
void l0032_xtable_dump(struct l0032_xtable *xtable);
const char* l0032_xtable_dump_entry_flags(struct l0032_xtable_entry *entry);

entry_handle l0032_get_entry(const char* name);
#endif